//定义小仓库
import { defineStore } from "pinia";
//引入请求函数
import {reqC1List,reqC2List,reqC3List} from '@/api/product/attr/attr';
import type { categoryStoreStateType } from './interface/category';
let useCategoryStore =  defineStore('category', {
    //存储数据
    state: ():categoryStoreStateType => {
        return {
             //存储一级分类的数据
             c1List:[],
             //收集一级分类的ID
             c1Id:'',
             c2Id:'',
             c2List:[],
             c3Id:'',
             c3List:[],
        }
    }
    ,
    //处理业务的地方
    actions:{
        async getC1List(){
             //获取一级分类的数据
             let result  = await reqC1List();
             console.log(result);
             this.c1List = result;   
        },
        async getC2List(){
            this.c2Id=''
            this.c3Id=''
            this.c3List=[]
            let result = await reqC2List(this.c1Id)
            console.log(result);
            this.c2List = result;
        },
        async getC3List(){
            this.c3Id=''
            let result = await reqC3List(this.c2Id)
            console.log(result);
            this.c3List = result;
        }
    }
});
//对外暴露
export default useCategoryStore;